package zone.haiwen.demo.domain.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.mapstruct.Mapper;
import zone.haiwen.demo.dto.Passenger;
import zone.haiwen.demo.dto.Travel;

/**
 * Description
 * @author zhangHaiWen
 * @date 2021/7/8 20:16
 * @return
 **/
@SuppressWarnings("ALL")
@Mapper
public interface TravelMapper extends BaseMapper<Travel> {
    /**
     * Description
     * @author zhangHaiWen
     * @date 2021/7/8 20:15
     * @return void
     **/
    @Select("create table `travel`(\n" +
            "    `id` bigint(20) not null comment'旅游id',\n" +
            "    `destination` VARCHAR(100) default null comment'目的地',\n" +
            "    `passenger_name` VARCHAR(20) default null comment'乘客姓名',\n" +
            "\t`passenger_id` bigint(20) not null comment'乘客id',\n" +
            "\t`gmt_create` varchar(10) not null comment'主动创建时间',\n" +
            "\t`gmt_modified` varchar(10) not null comment'被动更新时间',\n" +
            "\tPRIMARY KEY(`id`))ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='乘客旅行信息表';")
    void createTable();

    /**
     * Description
     * @author zhangHaiWen
     * @date 2021/7/8 20:15
     * @return void
     **/
    @Select("insert into travel (id, destination, passenger_name,passenger_id, gmt_create, gmt_modified) values(#{id}, #{destination}, #{passengerName}, #{passengerId}, #{gmtCreate}, #{gmtModified})")
    void insert(Long id, String destination, String passengerName, Long passengerId, String gmtCreate, String gmtModified);

    /**
     * Description
     * @author zhangHaiWen
     * @date 2021/7/8 20:15
     * @return com.baomidou.mybatisplus.core.metadata.IPage<zone.haiwen.demo.dto.Travel>
     **/
    @Select("select * from travel where destination = #{destination}")
    IPage<Travel> getTravelByDestination(Page page, @Param("destination") String destination);

    /**
     * Description
     * @author zhangHaiWen
     * @date 2021/7/8 20:45
     * @return com.baomidou.mybatisplus.core.metadata.IPage<zone.haiwen.demo.dto.Travel>
     **/
    @Select("SELECT t.id, t.destination, t.passenger_name, t.passenger_id From travel t LEFT join passenger p on t.passenger_id = p.id")
    IPage<Passenger> leftJoin(Page page);

}
